package com.sml.config;

import com.sml.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web拦截器配置类
 *
 * @author sml
 * @date 2024/7/10 15:09
 * @description TODO
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 登录拦截器注入
     */
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截器
        registry
                .addInterceptor(loginInterceptor)
                //登录接口允许访问。注册允许访问拦截
                .excludePathPatterns("/user/login", "/user/register");
    }
}
